from datetime import datetime
# 修改导入路径
from db.crud.agent import get_agent_by_userid, create_or_update_agent, delete_agent
from schemas.agent import AgentResponse, AgentBase


class AgentService:
    async def upsert_agent(self, agent_data: AgentBase) -> AgentResponse:
        try:
            db_agent = await create_or_update_agent({
                **agent_data.dict()
            })
      
            
            return AgentResponse(**db_agent) if db_agent else None

        except Exception as e:
     
            raise

       

    async def get_agent(self, userId: str) -> AgentResponse:
        db_agent = await get_agent_by_userid(userId)
        return AgentResponse(**db_agent) if db_agent else None

    async def delete_agent(self, userId: str) -> bool:
        result = await delete_agent(userId)
        return result